package com.cyj.calls;

import com.cyj.calls.model.Orders;

import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;

public class MyJobCallable implements Callable<Orders> {

    private List<Integer> list;

    private CountDownLatch countDownLatch;

    public MyJobCallable(List<Integer> list, CountDownLatch countDownLatch) {
        this.list = list;
        this.countDownLatch = countDownLatch;
    }

    @Override
    public Orders call() {
        Orders orders = new Orders();
        try {
            Long nums = list.stream().mapToLong(num -> num).sum();
            orders.setProductNum(nums);
            Long count = countDownLatch.getCount();
            if (count == 888L) {
                int a = 5 / 0;
            }
            orders.setProductName("apple" + nums);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            countDownLatch.countDown();
            return orders;
        }
    }

}
